package net.sjava.appstore;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import net.sjava.appstore.R;
import net.sjava.util.store.AmazonStoreApp;
import net.sjava.util.store.StoreApp;
import net.sjava.util.store.NaverStoreApp;
import net.sjava.util.store.PlayStoreApp;
import net.sjava.util.store.TStoreApp;

public class MainActivity extends Activity {
	private StoreApp store = null;
			
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        store = PlayStoreApp.newInstance();
        Log.d("MARKET", "Play Market 설치여부 : " + store.isInstalled(this));
        
        store = TStoreApp.newInstance();
        Log.d("MARKET", "TStore 설치여부 : " + store.isInstalled(this));
                
        store = AmazonStoreApp.newInstance();
        Log.d("MARKET", "Amazon Store 설치여부 : " + store.isInstalled(this));
        
        store = NaverStoreApp.newInstance();
        Log.d("MARKET", "NStore 설치여부 : " + store.isInstalled(this));
        
        //openTstore(MainActivity.this, pId);
    }
    
    public void onClick(View v) {
    	int vId = v.getId();
    	
    	// play
    	if(vId == R.id.btn_play) {
    		//  
    		store = PlayStoreApp.newInstance();
    		//store.open(this, "com.facebook.katana"); //  
    		//((PlayStore)store).search(this, "facebook");
    		((PlayStoreApp)store).openPublisherApps(this, "facebook");
    		
    		return;
    	}
    	
    	// tstore
    	if(vId == R.id.btn_tstore) {
    		//private static String pId = "0000320478";
    		store = TStoreApp.newInstance();
    		//store.openApp(this, "0000320478"); //  
    		store.searchApp(this, "facebook");
    		return;
    	}
    	
    	// amazon
    	if(vId == R.id.btn_amazon) {
    		store = AmazonStoreApp.newInstance();
    		//store.open(this, "com.amazon.mp3"); //  
    		//((AmazonStore)store).search(this, "mp3");
    		store.searchApp(this, "com.amazon.mp3");
    		return;
    	}
    	
    	// naver
    	if(vId == R.id.btn_nstore) {
    		store = NaverStoreApp.newInstance();
    		//store.openApp(this, "409160"); // 
    		store.searchApp(this, "naver");
    		return;
    	}
    }
    
}
